package Mainfunction;

import javax.swing.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class CheckAccount2 {
    private Connection connection;
    private String account;
    private JFrame frame;
    private String password;
    PreparedStatement stmt = null;
    ResultSet result = null;

    public CheckAccount2(JFrame frame, Connection connection, String account, String password) {
        this.frame = frame;
        this.account = account;
        this.password = password;
        this.connection = connection;
    }

    public boolean check() {
        try {
            String sql = "select * from teacherregister where username= ? and password= ? ";
            stmt = connection.prepareStatement(sql);
            stmt.setString(1, account);
            stmt.setString(2, password);
            result = stmt.executeQuery();
            if (result.next()) {
                JOptionPane.showMessageDialog(
                        frame,
                        "登录成功",
                        "Yes",
                        JOptionPane.INFORMATION_MESSAGE);
                return true;
            } else {
                return false;
            }

        } catch (Exception e) {
            return false;

        }


    }
}
